{include file="public/header" /}
<link href="/public/static/admin/assets/css/login.css" rel="stylesheet">
<!--[if lt IE 9]>
<meta http-equiv="refresh" content="0;ie.html" />
<![endif]-->
<script>
    if (window.top !== window.self) {
        window.top.location = window.location;
    }
</script>
</head>
<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-7">
            <div class="signin-info">
                <div class="logopanel m-b">
                    <h1>[ {:cache('site_name')} ]</h1>
                </div>
                <div class="m-b"></div>
                <h4>欢迎使用 <strong>{:cache('site_name')}</strong></h4>
                <ul class="m-b">
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势一</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势二</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势三</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势四</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势五</li>
                </ul>
                <strong>还没有账号？ <a href="#">立即注册&raquo;</a></strong>
            </div>
        </div>
        <div class="col-sm-5">
            <form method="post"  id="login-form">
                <h4 class="no-margins">登录：</h4>
                <p class="m-t-md">登录到后台管理系统</p>
                <input type="text" class="form-control uname" name="login_name" placeholder="用户名"  id="name"/>
                <input type="password" class="form-control pword m-b" name="pwd" placeholder="密码"  id="pwd"/>
                <!--验证码-->
                {if condition="cache('captcha_flag')==1"}
                <input type="text" class="form-control pword m-b" name="captcha" placeholder="验证码"  id="captcha"/>
                <div><img id="verify_img" src="{:captcha_src()}" alt="验证码" onclick="refreshVerify()">
                    <a href="javascript:refreshVerify()">点击刷新</a></div>
                <br/>
                {/if}
                <!--/验证码-->
                <div style="color:red;margin-bottom: 10px;" id="errMsg">{:cache('water_flag')}</div>
                <a href="">忘记密码了？</a>
                <button class="btn btn-success btn-block" onclick="login()" type="button">登录</button>
            </form>
        </div>
    </div>
    <div class="signup-footer">
        <div class="pull-left">
            &copy; 2018 All Rights Reserved. H+
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //回车登录
    $(document).keyup(function(event){
        if(event.keyCode ==13){
            login();
        }
    });

    /*登录*/
    function login() {
        //判空
        var name=$("#name").val();
        var pwd=$("#pwd").val();
        if(name==""){
            $("#errMsg").html("用户名不能为空！");
            return;
        }

        if(pwd==""){
            $("#errMsg").html("密码不能为空！");
            return;
        }
        {if condition="cache('captcha_flag')==1"}
        var captcha=$("#captcha").val();
        if(captcha==""){
            $("#errMsg").html("验证码不能为空！");
            return;
        }
        {/if}
        $.ajax({
            url: "{:U('admin/index/dologin')}",
            type: 'POST',
            dataType: 'json',
            data:$("#login-form").serializeJSON(),
            success: function (res) {
                if (res.rc == 0) {
                    location.replace("/admin/index/index");
                } else {
                    $("#errMsg").html(res.msg);
                    if(res.data==1){
                        refreshVerify();
                    }
                }
            }
        });
    }

    /**
     * 刷新验证码
     */
    function refreshVerify() {
        var ts = Date.parse(new Date())/1000;
        var img = document.getElementById('verify_img');
        img.src = "/captcha?id="+ts;
    }
</script>
